package com.relife.core.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * 部门
 * 
 * @author WU
 * 
 */
@Entity
@Table(name = "sys_department", uniqueConstraints = { @UniqueConstraint(columnNames = { "departCode" }) })
public class DepartmentEntity extends BaseEntity {

	private static final long serialVersionUID = 1L;

	private String name;
	private String departCode;
	private Integer type;
	private Integer orderBy;
	private DepartmentEntity parent;
	private List<DepartmentEntity> children;
	private List<DepartUserEntity> departUser;

	public DepartmentEntity() {
	}

	public DepartmentEntity(String id) {
		super.setId(id);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	@OrderBy(value = "orderBy ASC")
	public List<DepartmentEntity> getChildren() {
		return children;
	}

	public void setChildren(List<DepartmentEntity> children) {
		this.children = children;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Integer getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(Integer orderBy) {
		this.orderBy = orderBy;
	}

	public String getDepartCode() {
		return departCode;
	}

	public void setDepartCode(String departCode) {
		this.departCode = departCode;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "depart")
	public List<DepartUserEntity> getDepartUser() {
		return departUser;
	}

	public void setDepartUser(List<DepartUserEntity> departUser) {
		this.departUser = departUser;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID")
	public DepartmentEntity getParent() {
		return parent;
	}

	public void setParent(DepartmentEntity parent) {
		this.parent = parent;
	}

}
